<!-- 
 
server {
    listen 80;
    server_name example.com;

    # 静态资源根目录
    location / {
        root /var/www/html;  # 文件路径：/var/www/html/index.html
        index index.html index.htm;
        try_files $uri $uri/ =404;
    }
        或者
    location /static/ {
        alias /var/www/assets/;  # 注意：结尾有斜杠
        # 请求 /static/js/app.js → 实际读取 /var/www/assets/js/app.js
    }
}


server {
    listen 80;
    server_name example.com;

    # 1. HTML 文件
    location / {
        root /var/www/html;
        index index.html;
        try_files $uri $uri/ /index.html;  # 支持 SPA 路由
    }

    # 2. 静态资源目录（CSS, JS, 图片）
    location /static/ {
        alias /var/www/assets/;
        expires 1y;                    # 长期缓存
        add_header Cache-Control "public, immutable";
    }

    # 3. 图片资源（可单独优化）
    location ~* \.(jpg|jpeg|png|gif|webp|avif)$ {
        root /var/www/assets;
        expires 1y;
        add_header Cache-Control "public";
    }

    # 4. 字体文件
    location ~* \.(woff|woff2|eot|ttf|otf)$ {
        root /var/www/assets;
        expires 1y;
        add_header Access-Control-Allow-Origin "*";  # 允许跨域加载字体
    }

    # 5. Gzip 压缩（提升传输速度）
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml;

    # 6. 禁止访问敏感文件
    location ~* \.(env|config|lock|git) {
        deny all;
    }
}

-->